#include <glib.h>

static gpointer test_aqueue_push_func(gpointer data)
{
    GAsyncQueue *aqueue = NULL;

    g_print("%s \n", __FUNCTION__);
    g_print("delay 1 seconds to push data \n");
    g_usleep(1*1000*1000);

    aqueue = (GAsyncQueue *)data;

    g_async_queue_push(aqueue, GINT_TO_POINTER(99));

    return NULL;
}

static gpointer test_aqueue_pop_func(gpointer data)
{
    gpointer val = NULL;
    GAsyncQueue *aqueue = NULL;
    g_print("%s \n", __FUNCTION__);

    aqueue = (GAsyncQueue *)data;

    val = g_async_queue_try_pop(aqueue);
    g_print("val: %d \n", GPOINTER_TO_INT(val));

    g_print("delay 2 seconds to pop data \n");
    g_usleep(2*1000*1000);

    val = g_async_queue_try_pop(aqueue);
    g_print("val: %d \n", GPOINTER_TO_INT(val));

    val = g_async_queue_try_pop(aqueue);
    g_print("val: %d \n", GPOINTER_TO_INT(val));

    return NULL;
}

gint main(gint argc, gchar **argv)
{
    GThread *thd_push, *thd_pop;
    GAsyncQueue *aqueue = NULL;

    aqueue = g_async_queue_new();

    thd_push = g_thread_new("thd_push", test_aqueue_push_func, aqueue);
    thd_pop  = g_thread_new("thd_pop", test_aqueue_pop_func, aqueue);

    g_thread_join(thd_push);
    g_thread_join(thd_pop);

    g_async_queue_unref(aqueue);

    return 0;
}